package com.architecture.core.entity;

import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * LoginAction: Administrator
 * Date: 12-4-18
 * Time: 下午4:36
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "CORE_PERMISSION")
public class Permission extends BaseEntity {

//    @ManyToMany(fetch = FetchType.LAZY,targetEntity = Category.class,cascade = CascadeType.ALL,mappedBy = "permissionList")
//    private List<Category> permissionTypeList;

    @ManyToOne(fetch = FetchType.EAGER, targetEntity = Category.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "CATEGORY_ID")
    private Category category;

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = PermissionRole.class, cascade = CascadeType.ALL, mappedBy = "permissionList")
    private List<PermissionRole> permissionRoleList;              //权限角色，代表一系列权限的集合

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = Resource.class, cascade = CascadeType.ALL)
    @JoinTable(name = "EX_PERMISSION_RESOURCE", joinColumns = {@JoinColumn(name = "PERMISSION_ID")}, inverseJoinColumns = {@JoinColumn(name = "RESOURCE_ID")})
    private List<Resource> resourceList;

    @Column(name = "PERMISSION_TYPE")
    private int type;               //权限类型：1.新增；2.删除；3.修改；4.查询；5.审核

    @Column(name = "PERMISSION_NAME")             //权限名称
    private String name;

    @Column(name = "DEFAULT_ENABLE")
    private boolean defaultEnable;

    public List<PermissionRole> getPermissionRoleList() {
        return permissionRoleList;
    }

    public void setPermissionRoleList(List<PermissionRole> permissionRoleList) {
        this.permissionRoleList = permissionRoleList;
    }

    public List<Resource> getResourceList() {
        return resourceList;
    }

    public void setResourceList(List<Resource> resourceList) {
        this.resourceList = resourceList;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public boolean isDefaultEnable() {
        return defaultEnable;
    }

    public void setDefaultEnable(boolean defaultEnable) {
        this.defaultEnable = defaultEnable;
    }
}
